package com.itheima.d7_tcp4;

import java.io.*;
import java.net.Socket;
import java.net.SocketException;

public class ClientThread implements Runnable {
    private Socket socket;

    public ClientThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        //读取内容
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            while (true) {
                String s = br.readLine();
                System.out.println(socket.getInetAddress().getHostName() + " (" + socket.getInetAddress().getHostAddress() + ") " + ": " + s);
            }
        } catch (SocketException s){

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
